/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.administer.users;

import java.util.List;
import model.users.Speciality;
import view.controller.administer.users.ControllerEditUser;

/**
 *
 * @author Djordje Gligorijevic
 */
public class FrmEditUser extends javax.swing.JDialog {

    private ControllerEditUser controllerEditUser;

    /**
     * Creates new form FrmEditUser
     */
    public FrmEditUser(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtFUsername = new javax.swing.JTextField();
        txtFPassword = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtFFirstName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtFLastName = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtFEmail = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cbUsertype = new javax.swing.JComboBox();
        lblSpeciality = new javax.swing.JLabel();
        cbSpeciality = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Edit user"));

        jLabel1.setText("Username: ");

        jLabel2.setText("Password: ");

        jLabel3.setText("First name: ");

        jLabel4.setText("Last name: ");

        jLabel5.setText("Email: ");

        jLabel6.setText("User type: ");

        cbUsertype.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Client", "Expert", " " }));
        cbUsertype.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbUsertypeItemStateChanged(evt);
            }
        });

        lblSpeciality.setText("Speciality: ");

        cbSpeciality.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbSpecialityItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(43, 43, 43)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txtFPassword, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtFUsername, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtFFirstName, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(lblSpeciality))
                .addGap(43, 43, 43)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtFLastName)
                    .addComponent(txtFEmail)
                    .addComponent(cbUsertype, 0, 277, Short.MAX_VALUE)
                    .addComponent(cbSpeciality, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtFUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtFPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtFFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtFLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtFEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(cbUsertype, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSpeciality)
                    .addComponent(cbSpeciality, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jButton1.setText("Update user");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addGap(0, 15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbUsertypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbUsertypeItemStateChanged
        checkUsertype();
    }//GEN-LAST:event_cbUsertypeItemStateChanged

    private void cbSpecialityItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbSpecialityItemStateChanged
    }//GEN-LAST:event_cbSpecialityItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        controllerEditUser.updatePlayer();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmEditUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmEditUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmEditUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmEditUser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FrmEditUser dialog = new FrmEditUser(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbSpeciality;
    private javax.swing.JComboBox cbUsertype;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblSpeciality;
    private javax.swing.JTextField txtFEmail;
    private javax.swing.JTextField txtFFirstName;
    private javax.swing.JTextField txtFLastName;
    private javax.swing.JTextField txtFPassword;
    private javax.swing.JTextField txtFUsername;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the controllerEditUser
     */
    public ControllerEditUser getControllerEditUser() {
        return controllerEditUser;
    }

    /**
     * @param controllerEditUser the controllerEditUser to set
     */
    public void setControllerEditUser(ControllerEditUser controllerEditUser) {
        this.controllerEditUser = controllerEditUser;
    }

    /**
     * @return the cbSpeciality
     */
    public javax.swing.JComboBox getCbSpeciality() {
        return cbSpeciality;
    }

    /**
     * @param cbSpeciality the cbSpeciality to set
     */
    public void setCbSpeciality(javax.swing.JComboBox cbSpeciality) {
        this.cbSpeciality = cbSpeciality;
    }

    /**
     * @return the cbUsertype
     */
    public javax.swing.JComboBox getCbUsertype() {
        return cbUsertype;
    }

    /**
     * @param cbUsertype the cbUsertype to set
     */
    public void setCbUsertype(javax.swing.JComboBox cbUsertype) {
        this.cbUsertype = cbUsertype;
    }

    /**
     * @return the jButton1
     */
    public javax.swing.JButton getjButton1() {
        return jButton1;
    }

    /**
     * @param jButton1 the jButton1 to set
     */
    public void setjButton1(javax.swing.JButton jButton1) {
        this.jButton1 = jButton1;
    }

    /**
     * @return the jLabel1
     */
    public javax.swing.JLabel getjLabel1() {
        return jLabel1;
    }

    /**
     * @param jLabel1 the jLabel1 to set
     */
    public void setjLabel1(javax.swing.JLabel jLabel1) {
        this.jLabel1 = jLabel1;
    }

    /**
     * @return the jLabel2
     */
    public javax.swing.JLabel getjLabel2() {
        return jLabel2;
    }

    /**
     * @param jLabel2 the jLabel2 to set
     */
    public void setjLabel2(javax.swing.JLabel jLabel2) {
        this.jLabel2 = jLabel2;
    }

    /**
     * @return the jLabel3
     */
    public javax.swing.JLabel getjLabel3() {
        return jLabel3;
    }

    /**
     * @param jLabel3 the jLabel3 to set
     */
    public void setjLabel3(javax.swing.JLabel jLabel3) {
        this.jLabel3 = jLabel3;
    }

    /**
     * @return the jLabel4
     */
    public javax.swing.JLabel getjLabel4() {
        return jLabel4;
    }

    /**
     * @param jLabel4 the jLabel4 to set
     */
    public void setjLabel4(javax.swing.JLabel jLabel4) {
        this.jLabel4 = jLabel4;
    }

    /**
     * @return the jLabel5
     */
    public javax.swing.JLabel getjLabel5() {
        return jLabel5;
    }

    /**
     * @param jLabel5 the jLabel5 to set
     */
    public void setjLabel5(javax.swing.JLabel jLabel5) {
        this.jLabel5 = jLabel5;
    }

    /**
     * @return the jLabel6
     */
    public javax.swing.JLabel getjLabel6() {
        return jLabel6;
    }

    /**
     * @param jLabel6 the jLabel6 to set
     */
    public void setjLabel6(javax.swing.JLabel jLabel6) {
        this.jLabel6 = jLabel6;
    }

    /**
     * @return the jPanel1
     */
    public javax.swing.JPanel getjPanel1() {
        return jPanel1;
    }

    /**
     * @param jPanel1 the jPanel1 to set
     */
    public void setjPanel1(javax.swing.JPanel jPanel1) {
        this.jPanel1 = jPanel1;
    }

    /**
     * @return the lblSpeciality
     */
    public javax.swing.JLabel getLblSpeciality() {
        return lblSpeciality;
    }

    /**
     * @param lblSpeciality the lblSpeciality to set
     */
    public void setLblSpeciality(javax.swing.JLabel lblSpeciality) {
        this.lblSpeciality = lblSpeciality;
    }

    /**
     * @return the txtFEmail
     */
    public javax.swing.JTextField getTxtFEmail() {
        return txtFEmail;
    }

    /**
     * @param txtFEmail the txtFEmail to set
     */
    public void setTxtFEmail(javax.swing.JTextField txtFEmail) {
        this.txtFEmail = txtFEmail;
    }

    /**
     * @return the txtFFirstName
     */
    public javax.swing.JTextField getTxtFFirstName() {
        return txtFFirstName;
    }

    /**
     * @param txtFFirstName the txtFFirstName to set
     */
    public void setTxtFFirstName(javax.swing.JTextField txtFFirstName) {
        this.txtFFirstName = txtFFirstName;
    }

    /**
     * @return the txtFLastName
     */
    public javax.swing.JTextField getTxtFLastName() {
        return txtFLastName;
    }

    /**
     * @param txtFLastName the txtFLastName to set
     */
    public void setTxtFLastName(javax.swing.JTextField txtFLastName) {
        this.txtFLastName = txtFLastName;
    }

    /**
     * @return the txtFPassword
     */
    public javax.swing.JTextField getTxtFPassword() {
        return txtFPassword;
    }

    /**
     * @param txtFPassword the txtFPassword to set
     */
    public void setTxtFPassword(javax.swing.JTextField txtFPassword) {
        this.txtFPassword = txtFPassword;
    }

    /**
     * @return the txtFUsername
     */
    public javax.swing.JTextField getTxtFUsername() {
        return txtFUsername;
    }

    /**
     * @param txtFUsername the txtFUsername to set
     */
    public void setTxtFUsername(javax.swing.JTextField txtFUsername) {
        this.txtFUsername = txtFUsername;
    }

    private void checkUsertype() {
        if (String.valueOf(cbUsertype.getSelectedItem()).equals("Expert")) {
            lblSpeciality.setVisible(true);
            getCbSpeciality().setVisible(true);
        } else {
            lblSpeciality.setVisible(false);
            getCbSpeciality().setVisible(false);
        }
    }

    public void fillCBData() {
        getCbSpeciality().removeAllItems();
        List<Speciality> listOfSpecialities = controllerEditUser.getListOdSpecialities();
        for (Speciality speciality : listOfSpecialities) {
            getCbSpeciality().addItem(speciality);
        }
    }
}
